package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetExchange;
import com.example.yiwei.crm.entity.ExchangeEntity;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.util.SC;
import com.example.yiwei.crm.view.activity.healthActivity.detailedVisitActivity;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import org.json.JSONException;
import org.json.JSONObject;

import static com.example.yiwei.crm.R.id.detailed_doc_img_update;


public class JYDetailedJLActivity extends AppCompatActivity {
private ImageView img_back,img_update,img_tj,img_find,img_lr,img_me;
    private TextView sq_time,bf_time,jiaoliuliang,bf_fs,manger,yijian,cname,ctime;
    private ExchangeEntity exchange;
    private ImageView img_delete;
    private String result;
    SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jydetailed_jl);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        img_delete= (ImageView) findViewById(R.id.detailed_jl_img_delete);
        img_back= (ImageView) findViewById(R.id.detailed_doc_img_back);
        img_update= (ImageView) findViewById(R.id.detailed_doc_img_update);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        img_lr= (ImageView) findViewById(R.id.item_image_lr);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        img_find= (ImageView) findViewById(R.id.item_image_cx);
        sq_time = (TextView) findViewById(R.id.jl_sq_time);
        bf_time = (TextView) findViewById(R.id.jl_bf_time);
        jiaoliuliang = (TextView) findViewById(R.id.jl_jiaoliulang);
        bf_fs = (TextView) findViewById(R.id.jl_bf_fs);
        manger = (TextView) findViewById(R.id.jl_manger);
        yijian = (TextView) findViewById(R.id.jl_yijian);
        cname = (TextView) findViewById(R.id.jl_cname);
        ctime = (TextView) findViewById(R.id.jl_ctime);
        exchange = GetExchange.exchangeEntity;
        sq_time.setText(exchange.getSq_time());
        bf_time.setText(exchange.getBf_time());
        bf_fs.setText(exchange.getFs_name());
        jiaoliuliang.setText(exchange.getJiaoliuliang());
        manger.setText(exchange.getManger_name());
        yijian.setText(exchange.getYijian());
        cname.setText(exchange.getCname());
        ctime.setText(exchange.getCtime());
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

       img_lr.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Intent intent=new Intent(JYDetailedJLActivity.this, JDcoorActivity.class);
             startActivity(intent);
               finish();

           }
       });
        img_tj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedJLActivity.this, JDcoorActivity.class);
                intent.putExtra("tt","tt");
                startActivity(intent);
                finish();
            }
        });
        img_find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedJLActivity.this, JDcoorActivity.class);
                intent.putExtra("ii","ii");
                startActivity(intent);
                finish();
            }
        });
        img_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedJLActivity.this, JDcoorActivity.class);
                intent.putExtra("me","me");
                startActivity(intent);
                finish();
            }
        });
        img_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(new ContextThemeWrapper(JYDetailedJLActivity.this, R.style.custom_dialog));
                builder.setTitle("您确定要删除吗？");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                SC sc = new SC();
                                JSONObject object = sc.storage(sp);
                                try {
                                    object.put("KJA01",exchange.getId());
                                    object.put("KXA01",exchange.getCoor_id());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                String json = object.toString();
                                result= NetWorkUtils.getCount(baseClass.delete_jl_url,json);
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            JSONObject object=new JSONObject(result);
                                            boolean boolen=object.getBoolean("ifsuccess");
                                            if (boolen){
                                                finish();
                                            }
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                });
                            }
                        }).start();

                    }
                });

                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.show();
            }
        });
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        img_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedJLActivity.this,JYAddJLActivity.class);
                intent.putExtra("tag","update");
                startActivity(intent);
                finish();
            }
        });
    }
}
